home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / gawk-3.000 / gawk-3 / gawk-3.0.0 / posix / gawkmisc.c < prev   
Encoding:
C/C++ Source or Header  |  1995-12-29  |  2.6 KB  |  116 lines

  1. /*
  2.  * gawkmisc.c --- miscellanious gawk routines that are OS specific.
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989, 1991 - 95 the Free Software Foundation, Inc.
  7.  * 
  8.  * This file is part of GAWK, the GNU implementation of the
  9.  * AWK Programming Language.
  10.  * 
  11.  * GAWK is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  * 
  16.  * GAWK is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  24.  */
  25.  
  26. char quote = '\'';
  27. char *defpath = DEFPATH;
  28. char envsep = ':';
  29.  
  30. /* gawk_name --- pull out the "gawk" part from how the OS called us */
  31.  
  32. char *
  33. gawk_name(filespec)
  34. const char *filespec;
  35. {
  36.     char *p;
  37.     
  38.     /* "path/name" -> "name" */
  39.     p = strrchr(filespec, '/');
  40.     return (p == NULL ? (char *) filespec : p + 1);
  41. }
  42.  
  43. /* os_arg_fixup --- fixup the command line */
  44.  
  45. void
  46. os_arg_fixup(argcp, argvp)
  47. int *argcp;
  48. char ***argvp;
  49. {
  50.     /* no-op */
  51.     return;
  52. }
  53.  
  54. /* os_devopen --- open special per-OS devices */
  55.  
  56. int
  57. os_devopen(name, flag)
  58. const char *name;
  59. int flag;
  60. {
  61.     /* no-op */
  62.     return INVALID_HANDLE;
  63. }
  64.  
  65. /* optimal_bufsize --- determine optimal buffer size */
  66.  
  67. int
  68. optimal_bufsize(fd, stb)
  69. int fd;
  70. struct stat *stb;
  71. {
  72.     /* force all members to zero in case OS doesn't use all of them. */
  73.     memset(stb, '\0', sizeof(struct stat));
  74.  
  75.     /*
  76.      * System V.n, n < 4, doesn't have the file system block size in the
  77.      * stat structure. So we have to make some sort of reasonable
  78.      * guess. We use stdio's BUFSIZ, since that is what it was
  79.      * meant for in the first place.
  80.      */
  81. #ifdef HAVE_ST_BLKSIZE
  82. #define DEFBLKSIZE    (stb->st_blksize ? stb->st_blksize : BUFSIZ)
  83. #else
  84. #define    DEFBLKSIZE    BUFSIZ
  85. #endif
  86.  
  87.     if (isatty(fd))
  88.         return BUFSIZ;
  89.     if (fstat(fd, stb) == -1)
  90.         fatal("can't stat fd %d (%s)", fd, strerror(errno));
  91.     if (lseek(fd, (off_t)0, 0) == -1)    /* not a regular file */
  92.         return DEFBLKSIZE;
  93.     if (stb->st_size > 0 && stb->st_size < DEFBLKSIZE) /* small file */
  94.         return stb->st_size;
  95.     return DEFBLKSIZE;
  96. }
  97.  
  98. /* ispath --- return true if path has directory components */
  99.  
  100. int
  101. ispath(file)
  102. const char *file;
  103. {
  104.     return (strchr(file, '/') != NULL);
  105. }
  106.  
  107. /* isdirpunct --- return true if char is a directory separator */
  108.  
  109. int
  110. isdirpunct(c)
  111. int c;
  112. {
  113.     return (c == '/');
  114. }
  115.  
  116.